package com.example.games.core;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.util.Log;

/**
 * 
 * 
 * @author caohao
 * 
 */
public class GameHelper {

	private static boolean drawFPS = true;

	private static boolean debug = true;

	private static int screenWidth, screenHeight;

	private static Context context;

	public static Context getContext() {
		return context;
	}

	public static void setContext(Context ctx) {
		context = ctx;
	}

	public static boolean isDrawFPS() {
		return drawFPS;
	}

	public static void setDebug(boolean dug) {
		debug = dug;
	}

	public static void setDrawFPS(boolean drawFps) {
		drawFPS = drawFps;
	}

	public static int getScreenWidth() {
		return screenWidth;
	}

	public static void setScreenWidth(int width) {
		screenWidth = width;
	}

	public static int getScreenHeight() {
		return screenHeight;
	}

	public static void setScreenHeight(int height) {
		screenHeight = height;
	}

	public static boolean isDebug() {
		return debug;
	}

	public static void printLog(String msg) {
		if (debug) {
			Log.e("<Log> CGame ", msg);
		}
	}

	/**
	 * 分割图片
	 * 
	 * @param bitmap
	 * @param x
	 * @param y
	 * @param w
	 * @param h
	 * @return
	 */
	public static Bitmap clipBitmap(Bitmap bitmap, int x, int y, int w, int h) {
		Bitmap tmp = Bitmap.createBitmap(bitmap, x, y, w, h);
		if (w > 64 && h > 64) {
			tmp = resizeImage(tmp, 64, 64);
		}
		return tmp;
	}

	// 调整图片大小
	public static Bitmap resizeImage(Bitmap bitmap, int w, int h) {
		Bitmap BitmapOrg = bitmap;
		int width = BitmapOrg.getWidth();
		int height = BitmapOrg.getHeight();
		int newWidth = w;
		int newHeight = h;
		float scaleWidth = ((float) newWidth) / width;
		float scaleHeight = ((float) newHeight) / height;
		Matrix matrix = new Matrix();
		matrix.postScale(scaleWidth, scaleHeight);
		Bitmap resizedBitmap = Bitmap.createBitmap(BitmapOrg, 0, 0, width,
				height, matrix, true);
		return resizedBitmap;
	}

}
